#!/bin/bash
##IModule 
#↑用的时候把第一个"#"去掉

#########################
#   名称: BasicConfigManager
#   用途: 提供简单的读写功能
#   命名空间: BasicCM
#########################

#shellcheck disable=SC1090
#shellcheck disable=SC2164

#_BasicCM_替换成组件命名空间
if [ -z "$_BasicCM_Loaded" ];then
    function _framework_resolve_dependencies()
    {
        true;
    }

    #配置文件
    readonly _BasicCM_File="_BasicCM.ini";
    readonly _BasicCM_HERE="$(cd "$(dirname "${BASH_SOURCE:-$0}")";pwd)";
    readonly _BasicCM_CONFIG_NAMESPACE="$(basename "${BASH_SOURCE:-$0}")";
    source "$_BasicCM_HERE/IniConfig";
    
    function _BasicCM_InitConfigFile()
    {
        if [ ! -f "$_BasicCM_File" ];then
            touch "$_BasicCM_File";
        fi;
        #在这条注释下面添加代码
    }
    
    function _BasicCM_GetValue()
    {
        local key="$1";
        local value="";
    
        if value="$(_IniConfig_ReadOptionFromFile "$_BasicCM_File" "$_BasicCM_CONFIG_NAMESPACE" "$key")";then
            echo "$value";
        else
            return 1;
        fi;
    }
    
    function _BasicCM_SetValue()
    {
        local key="$1";
        local value="$2";
    
        if [ -z "$key" ] || [ -z "$value" ];then
            return 1;
        fi;
    
        _IniConfig_WriteOptionToFile "$_BasicCM_File" "$_BasicCM_CONFIG_NAMESPACE" "$key" "$value";
    }
    readonly _BasicCM_Loaded=true;
fi;